package com.qindian.coupontest;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Button;

import java.util.List;

public class MainActivity extends BaseActivity {

    private List<Fragment> mFragmentList;
    private int mWidth, mHeight;
    private Button mButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mButton = findViewById(R.id.coupons);
        mButton.post(new Runnable() {
            @Override
            public void run() {
                  mWidth=mButton.getWidth();
                  mHeight=mButton.getHeight();
            }
        });
    }

    public void choosePlatform(View view) {
        Intent intent = new Intent(this, GoodsListActivity2.class);
        switch (view.getId()) {
            case R.id.tb:
                intent.putExtra("platform", "tbgoods");
                intent.putExtra("type", "tb");
                intent.putExtra("detail", "tbdetail");
                startActivity(intent);

                break;
            case R.id.jd:
                intent.putExtra("platform", "jdgoods");
                intent.putExtra("type", "jd");
                intent.putExtra("detail", "jddetail");
                startActivity(intent);
                break;
            case R.id.coupons:
//                Observable.create(new ObservableOnSubscribe<String>() {
//                    @Override
//                    public void subscribe(ObservableEmitter<String> e) throws Exception {
//                        Log.e("tag", "subscribe: " + Thread.currentThread().getName());
//                        final DatagramSocket socket = new DatagramSocket(9998);
//                        byte[] result = new byte[1024];
//                        final DatagramPacket packet = new DatagramPacket(result, 0, result.length);
//                        while (true) {
//                            socket.receive(packet);
//                            final String content = new String(packet.getData());
//                            Log.e("tag", "subscribe: " + content);
//                            e.onNext(content);
//                        }
//                    }
//                }).subscribeOn(Schedulers.newThread())
//                        .observeOn(AndroidSchedulers.mainThread())
//                        .subscribe(new Observer<String>() {
//                            @Override
//                            public void onSubscribe(Disposable d) {
//
//                            }
//
//                            @Override
//                            public void onNext(final String s) {
//                                showToast(s);
//
//                            }
//
//                            @Override
//                            public void onError(Throwable e) {
//                            }
//
//                            @Override
//                            public void onComplete() {
//
//                            }
//                        });
                showToast(mWidth+"|"+mHeight);
//                startActivity(new Intent(this, ExchangedCouponListActivity.class));
                break;
        }
    }
}
